package jmini.examples.spring;

import java.io.File;
import java.io.IOException;

import jmini.iservice.IMiniService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class SpringEnv {
	
	public static Logger logger = LoggerFactory.getLogger(SpringEnv.class);
	
	private static AbstractApplicationContext springctx = null;
	
	public static IMiniService getMiniService(){
		return (IMiniService)springctx.getBean("miniService");
	}
	
	public static void init() throws IOException{
		logger.info("jmini spring init.");
		File sysconfig = new File("conf/jmini_example.conf");
		logger.info("jmini example load config from {}", sysconfig.getAbsolutePath());
		Props.load(sysconfig);
		logger.info("jmini example load config ok.");
		
		logger.info("jmini example load spring start.");
		springctx = new ClassPathXmlApplicationContext(new String[]{"classpath*:spring-jmini-fw.xml"});
		logger.info("jmini example load spring ok.");
	}

	public static void destroy() {
		springctx.close();
		logger.info("spring destroied.");
	}

}
